package com.cfpl.project_common.exception;

import com.cfpl.project_common.enums.CodeEnum;
import com.cfpl.project_common.result.BaseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler{


    @ExceptionHandler(BusException.class)
    public BaseResult busException(BusException busException){
        log.info("*******捕获业务异常 ***********");
        return new BaseResult<>(busException.getErr_code(), busException.getErr_message(), null);
    }

    @ExceptionHandler(Exception.class)
    public BaseResult busException(Exception exception){
        log.info("*******捕获系统异常 ***********");
//        exception.printStackTrace();
        log.info("{}",exception.getMessage());
        return new BaseResult<>(CodeEnum.SYSTEM_ERROR.getCode(),CodeEnum.SYSTEM_ERROR.getMessage(), null);
    }




}
